const app = getApp();
var DB = require("../../utils/CloudDB.js")
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    ColorList: app.globalData.ColorList,
  },
  onLoad: function () {
    wx.cloud.callFunction({
      name: 'login',
      data: {},
      success: res => {
        DB.selectRow("user", {
          _openid: res.result.openid
        }, function (res) {
          if (res.data.length > 0) {
            app.globalData.userInfo = res.data[0];
            wx.redirectTo({
              url: '/pages/index/index',
            })
          }else{
            wx.redirectTo({
              url: '/pages/login/index',
            })
          }
        })
      },
    })
  }
});
